/**
 * 
 */
package craneding.gwt.test.server;

import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;

import craneding.gwt.test.client.domain.JobNotesService;
import craneding.gwt.test.client.jobnotes.JobNotes;

/**
 * @author crane.ding
 * @version 1.0 2008-12-6
 */
public class JobNotesServiceImpl extends RemoteServiceServlet implements
		JobNotesService {
	private static final long serialVersionUID = -7261980462976974576L;

	public List<JobNotes> queryJobNotes(JobNotes jobNotes) {
		List<JobNotes> jobNotesArray = new ArrayList<JobNotes>();
		int len = 18;
		if (jobNotes == null)
			len = 60;
		for (int i = 0; i < len; i++) {
			JobNotes notes = new JobNotes();
			notes.setCreationDate(new Date());
			notes.setId(i);
			notes.setProcessingStatus("待处理");
			notes.setProcessors("processor" + i);
			notes.setRemark("nonthing");
			notes.setSponsor("sponsor" + i);
			notes.setStatus(JobNotes.JobNotesStatus.Xtk);
			notes.setTitle("title" + i);
			notes.setTransCode("transCode" + i);
			notes.setType(JobNotes.JobNotesTypes.Snydjfdb);
			jobNotesArray.add(notes);
			if (jobNotes != null)
				try {
					BeanInfo beanInfo = Introspector
							.getBeanInfo(JobNotes.class);
					PropertyDescriptor[] descriptors = beanInfo
							.getPropertyDescriptors();
					for (PropertyDescriptor descriptor : descriptors) {
						Method readMethod = descriptor.getReadMethod();
						Method writeMethod = descriptor.getWriteMethod();
						if (readMethod != null && writeMethod != null) {
							Object ob = readMethod.invoke(jobNotes,
									new Object[] {});
							if (ob != null&&!ob.toString().equals(""))
								writeMethod.invoke(notes, ob);
						}
					}
				} catch (IntrospectionException e) {
					e.printStackTrace();
				} catch (IllegalArgumentException e) {
					e.printStackTrace();
				} catch (IllegalAccessException e) {
					e.printStackTrace();
				} catch (InvocationTargetException e) {
					e.printStackTrace();
				}
		}
		return jobNotesArray;
	}

}
